home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3082 / 3082.xpi / components / undoclosedtabsbutton.js
Text File  |  2006-08-23  |  4KB  |  120 lines

  1. function undoClosed() {}
  2.  
  3. undoClosed.prototype = {
  4.  
  5.     observe: function(subject, topic, data)
  6.     {
  7.         if (topic == 'app-startup')
  8.         {
  9.             this.observerService = Components.classes['@mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService);
  10.             this.observerService.addObserver(this, 'profile-after-change', false);
  11.             this.observerService.addObserver(this, 'xpcom-shutdown', false);
  12.         }
  13.         else if (topic == 'profile-after-change')
  14.         {
  15.             var ioService = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
  16.             var styleSheetService = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);
  17.             var prefBranch = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getBranch('extensions.undoclosedtabsbutton.');
  18.             var prefs = prefBranch.getChildList('', {});
  19.             for (var i = 0; i < prefs.length; i++)
  20.             {
  21.                 if (prefBranch.getBoolPref(prefs[i]) && prefs[i].indexOf('.') == -1)
  22.                 {
  23.                     try
  24.                     {
  25.                         var sheet = ioService.newURI('chrome://undoclosedtabsbutton/skin/' + prefs[i] + '.css', null, null);
  26.                         styleSheetService.loadAndRegisterSheet(sheet, styleSheetService.AGENT_SHEET);
  27.                     }
  28.                     catch (ex)
  29.                     {
  30.                         prefBranch.clearUserPref(prefs[i]);
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.         else if (topic == 'xpcom-shutdown')
  36.         {
  37.             this.observerService.removeObserver(this, 'profile-after-change');
  38.             this.observerService.removeObserver(this, 'xpcom-shutdown');
  39.             this.observerService = null;
  40.         }
  41.     },
  42.     
  43.     QueryInterface: function(iid)
  44.     {
  45.         if (iid.equals(Components.interfaces.nsIObserver) || iid.equals(Components.interfaces.nsISupports))
  46.         {
  47.             return this;
  48.         }
  49.         else
  50.         {
  51.             throw Components.results.NS_ERROR_NO_INTERFACE;
  52.         }
  53.     }
  54. }
  55.  
  56. var undoClosedModuleFactory = {
  57.  
  58.     NAME: 'undoclosedtabsbutton@supernova00.biz',
  59.     
  60.     CID: Components.ID('{9e7f8f70-2792-11db-a98b-0800200c9a66}'),
  61.     
  62.     CONTRACT_ID: '@supernova00.biz/undoclosedtabsbutton;1',
  63.     
  64.     IMPLEMENTATION: undoClosed,
  65.     
  66.     registerSelf: function(compMgr, fileSpec, location, type)
  67.     {
  68.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  69.         compMgr.registerFactoryLocation(this.CID, this.NAME, this.CONTRACT_ID, fileSpec, location, type);
  70.         
  71.         var categoryManager = Components.classes['@mozilla.org/categorymanager;1'].getService(Components.interfaces.nsICategoryManager);
  72.         categoryManager.addCategoryEntry('app-startup', this.NAME, 'service,' + this.CONTRACT_ID, true, true);
  73.     },
  74.     
  75.     unregisterSelf: function(compMgr, fileSpec, location)
  76.     {
  77.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  78.         compMgr.unregisterFactoryLocation(this.CID, fileSpec);
  79.         
  80.         var categoryManager = Components.classes['@mozilla.org/categorymanager;1'].getService(Components.interfaces.nsICategoryManager);
  81.         categoryManager.deleteCategoryEntry('app-startup', this.NAME, true);
  82.     },
  83.     
  84.     getClassObject: function(compMgr, cid, iid)
  85.     {
  86.         if (!iid.equals(Components.interfaces.nsIFactory))
  87.         {
  88.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  89.         }
  90.         
  91.         if (cid.equals(this.CID))
  92.         {
  93.             return this;
  94.         }
  95.         else
  96.         {
  97.             throw Components.results.NS_ERROR_NO_INTERFACE;
  98.         }
  99.     },
  100.     
  101.     canUnload: function(compMgr)
  102.     {
  103.         return true;
  104.     },
  105.     
  106.     createInstance: function(outer, iid)
  107.     {
  108.         if (outer)
  109.         {
  110.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  111.         }
  112.         
  113.         return (new this.IMPLEMENTATION()).QueryInterface(iid);
  114.     }
  115. };
  116.  
  117. function NSGetModule(compMgr, fileSpec)
  118. {
  119.     return undoClosedModuleFactory;
  120. }